'''
Created on 10/09/2009

@author: Edward
'''
from ConfigParser import RawConfigParser
from spear.wsdl import WSDL, Element
import os
import unittest


class WSDLTest(unittest.TestCase):


    def setUp(self):
        section = 'a2a data'
        properties_file_path = os.path.dirname(__file__) + '/a2a.properties'
        self.cp = RawConfigParser()
        self.cp.read(properties_file_path)
        self.wsdl_path = self.cp.get(section, 'wsdlpath')


    def tearDown(self):
        pass

    def test_get_element_dictionary(self):
        '''[WSDL] test get_element_dictionary'''
        wsdl_file = open(self.wsdl_path + 'LxSpearApplication_2_0.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        element_dictionary = wsdl.element_dictionary
        self.assertEqual(element_dictionary['getApplicationResponse.getApplicationReturn.application'].name, 'application')
        self.assertEqual(element_dictionary['getApplicationResponse.getApplicationReturn.application'].type, '{http://application.response.was6.webservice.spear.lx.dse.vic.gov.au}Application_2_0')
        self.assertEqual(element_dictionary['getApplicationResponse.getApplicationReturn.application'].ns, 'http://application.response.was6.webservice.spear.lx.dse.vic.gov.au')
        self.assertEqual(element_dictionary['getApplicationResponse.getApplicationReturn.application'].array, False)
        
    def test_get_types_dictionary(self):
        '''[WSDL] test get_types_dictionary'''
        document_type_element = Element('documentType', '{http://www.w3.org/2001/XMLSchema}string', 'http://application.response.webservice.spear.lx.dse.vic.gov.au')
        id = Element('id', '{http://www.w3.org/2001/XMLSchema}long', 'http://application.response.webservice.spear.lx.dse.vic.gov.au')
        versions = Element('versions', '{http://application.response.webservice.spear.lx.dse.vic.gov.au}Version', 'http://application.response.webservice.spear.lx.dse.vic.gov.au', True)
        recheck = Element('recheck', '{http://www.w3.org/2001/XMLSchema}boolean', 'http://application.response.webservice.spear.lx.dse.vic.gov.au')
        document_cc_version = Element('documentCcVersion', '{http://www.w3.org/2001/XMLSchema}int', 'http://application.response.webservice.spear.lx.dse.vic.gov.au')
        elements = [document_type_element, id, versions, recheck, document_cc_version]
        
        wsdl_file = open(self.wsdl_path + 'LxSpearApplication_2_0.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        types_dictionary = wsdl.types_dictionary
        document_elements = types_dictionary['{http://application.response.webservice.spear.lx.dse.vic.gov.au}Document'].elements
        self.assertEqual(document_elements, elements)
        
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()